package com.cxc.singleton;

/**
 * 双重检查锁实现单例模式
 * author cxc  一般不建议使用
 */
public class DoubleCheckSingleton {

    private  static DoubleCheckSingleton instance = null;

    private DoubleCheckSingleton() {

    }

    public static DoubleCheckSingleton getInstance() {
        if (instance == null) {
            DoubleCheckSingleton dcs;
            synchronized (DoubleCheckSingleton.class) {
                dcs = instance;
                if (null == dcs) {
                    synchronized (DoubleCheckSingleton.class) {
                        if( null  == dcs) {
                            dcs = new DoubleCheckSingleton();
                        }
                    }
                    instance = dcs;
                }
            }
        }
        return instance;
    }

}
